﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace Orm.LinqParse
{
    /// <summary>
    /// 谓词
    /// </summary>
    internal class Predicate
    {
        public Predicate()
        {
            this.SqlText = new Queue<string>();
        }

        public Queue<string> SqlText { get; set; }

        public string GetSqlText()
        {
            StringBuilder sb = new StringBuilder();
            string tmp = string.Empty; ;
            foreach (string sqlText in SqlText)
            {
                if (sqlText == "NULL" && tmp == " = ")//转换成判断空语句 IS NULL
                {
                    sb.Remove(sb.Length - 3, 3);
                    sb.Append(" IS NULL ");
                }
                else if (sqlText == "NULL" && tmp == " <> ")//转换成判断非空语句 IS NOT NULL
                {
                    sb.Remove(sb.Length - 4, 4);
                    sb.Append(" IS NOT NULL ");
                }
                else
                {
                    sb.Append(sqlText);
                }
                tmp = sqlText;
            }
            return sb.ToString();
        }
    }
}
